package com.fangzhi.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fangzhi.mapper.AdminAccountRoleDeptRelationMapper;
import com.fangzhi.mobel.AdminAccountRoleDeptRelation;
import com.fangzhi.mobel.RoleBaseInfo;
import com.fangzhi.mobel.vo.LoginVo;
import com.fangzhi.mobel.vo.RoleListVo;
import com.fangzhi.service.AdminAccountRoleDeptRelationService;
import com.fangzhi.service.RoleBaseInfoService;
import com.fangzhi.mapper.RoleBaseInfoMapper;
import com.fangzhi.utils.BeanCopyUtil;
import com.fangzhi.utils.GlobalParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* @author edy
* @description 针对表【role_base_info】的数据库操作Service实现
* @createDate 2024-09-11 20:07:35
*/
@Service
public class RoleBaseInfoServiceImpl extends ServiceImpl<RoleBaseInfoMapper, RoleBaseInfo>
    implements RoleBaseInfoService{

    @Autowired
    private AdminAccountRoleDeptRelationMapper adminAccountRoleDeptRelationMapper;

    @Override
    public List<RoleListVo> roleList(Integer role) {
        LoginVo loginVo = GlobalParam.LOGIN_ACCOUNT_INFO.get();
        AdminAccountRoleDeptRelation adminAccountRoleDeptRelation = adminAccountRoleDeptRelationMapper.selectOne(Wrappers
                .<AdminAccountRoleDeptRelation>lambdaQuery().eq(AdminAccountRoleDeptRelation::getAdminAccounntId, loginVo.getId()));
        List<RoleListVo> copy = new ArrayList<>();
        if (adminAccountRoleDeptRelation.getRoleId() == 1 || adminAccountRoleDeptRelation.getRoleId() == 6){
            List<RoleBaseInfo> roleBaseInfos = this.getBaseMapper().selectList(Wrappers.<RoleBaseInfo>lambdaQuery()
                    .eq(role > 0, RoleBaseInfo::getId, role));
            copy = BeanCopyUtil.copy(roleBaseInfos, RoleListVo.class);
        }else if (adminAccountRoleDeptRelation.getRoleId() == 2){
            List<RoleBaseInfo> roleBaseInfos = this.getBaseMapper().selectList(Wrappers.<RoleBaseInfo>lambdaQuery()
                    .eq(role > 0, RoleBaseInfo::getId, role).in(RoleBaseInfo::getId, Arrays.asList(2, 3)));
            copy = BeanCopyUtil.copy(roleBaseInfos, RoleListVo.class);
        }else if (adminAccountRoleDeptRelation.getRoleId() == 3){
            List<RoleBaseInfo> roleBaseInfos = this.getBaseMapper().selectList(Wrappers.<RoleBaseInfo>lambdaQuery()
                    .eq(role > 0, RoleBaseInfo::getId, role).in(RoleBaseInfo::getId, Collections.singletonList(3)));
            copy = BeanCopyUtil.copy(roleBaseInfos, RoleListVo.class);
        }else if (adminAccountRoleDeptRelation.getRoleId() == 4 || adminAccountRoleDeptRelation.getRoleId() == 5){
            List<RoleBaseInfo> roleBaseInfos = this.getBaseMapper().selectList(Wrappers.<RoleBaseInfo>lambdaQuery()
                    .eq(role > 0, RoleBaseInfo::getId, role).in(RoleBaseInfo::getId, Arrays.asList(1, 2, 3, 4, 5, 6)));
            copy = BeanCopyUtil.copy(roleBaseInfos, RoleListVo.class);
        }
//        else if (adminAccountRoleDeptRelation.getRoleId() == 5){
//            List<RoleBaseInfo> roleBaseInfos = this.getBaseMapper().selectList(Wrappers.<RoleBaseInfo>lambdaQuery()
//                    .eq(role > 0, RoleBaseInfo::getId, role).in(RoleBaseInfo::getId, Arrays.asList(1, 2, 3, 4, 5, 6)));
//            copy = BeanCopyUtil.copy(roleBaseInfos, RoleListVo.class);
//        }
        return copy;
    }
}




